#include<iostream>
#include<cmath>
#include<string>
using namespace std;
typedef long long LL;
LL a, b, p;
int main()
{
	cin >> a >> b >> p;
	LL ans = 0;
	while (b) {
		if (b & 1)ans = (ans + a) % p;
		a = a * 2 % p;
		b >>= 1;
	}
	cout << ans << endl;
	return 0;
}